home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / SCROLLER.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  5KB  |  177 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1991, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.5  $
  6. //
  7. // Definition of class TScroller.
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_SCROLLER_H)
  10. #define OWL_SCROLLER_H
  11.  
  12. #if !defined(OWL_DEFS_H)
  13. # include <owl/defs.h>
  14. #endif
  15. #if !defined(CLASSLIB_OBJSTRM_H)
  16. # include <classlib/objstrm.h>
  17. #endif
  18. #if !defined(__LIMITS_H)
  19. # include <limits.h>
  20. #endif
  21.  
  22. #if defined(BI_NAMESPACE)
  23. namespace OWL {
  24. #endif
  25.  
  26. // Generic definitions/compiler options (eg. alignment) preceeding the
  27. // definition of classes
  28. #include <services/preclass.h>
  29.  
  30. class _OWLCLASS TWindow;
  31. #if !defined(WINSYS_GEOMETRY_H)
  32.  class _BIDSCLASS TRect;
  33. #endif
  34. class _OWLCLASS TDC;
  35.  
  36. inline long LongMulDiv(long mul1, long mul2, long div1)
  37.                        {return (mul1*mul2) / div1;}
  38.  
  39. //
  40. // class TScroller
  41. // ~~~~~ ~~~~~~~~~
  42. // Class TScroller implements the actual scroller object. All functions
  43. // are inline or virtual to avoid pulling in code when no scrollers have
  44. // been constructed.
  45. //
  46. class _OWLCLASS TScroller : public TStreamableBase {
  47.   public:
  48.     TScroller(TWindow* window,
  49.               int      xUnit,  int  yUnit,
  50.               long     xRange, long yRange);
  51.     virtual ~TScroller();
  52.  
  53.             void  SetWindow(TWindow* win);
  54.     virtual void  SetUnits(int xUnit, int yUnit);
  55.     virtual void  SetPageSize();
  56.     virtual void  SetSBarRange();
  57.     virtual void  SetRange(long xRange, long yRange);
  58.     virtual void  SetTotalRangeOfUnits(long xTotalUnits, long yTotalUnits);
  59.  
  60.     virtual void  BeginView(TDC& dc, TRect& rect);
  61.     virtual void  EndView();
  62.     virtual void  VScroll(uint scrollEvent, int thumbPos);
  63.     virtual void  HScroll(uint scrollEvent, int thumbPos);
  64.     virtual void  ScrollTo(long x, long y);
  65.  
  66.     // Scrolls to a position calculated using the passed delta values
  67.     //
  68.     void          ScrollBy(long dx, long dy);
  69.  
  70.     virtual bool  IsAutoMode();
  71.     virtual void  AutoScroll();
  72.  
  73.     // Returns a bool value indicating whether or not the passed
  74.     // area (in units) is currently visible
  75.     //
  76.     bool          IsVisibleRect(long x, long y, int xExt, int yExt);
  77.  
  78.     // Converts a horizontal range value from the scrollbar to a
  79.     // horizontal scroll value
  80.     //
  81.     int           XScrollValue(long rangeUnit);
  82.  
  83.     // Converts a vertical range value from the scrollbar to a
  84.     // vertical scroll value
  85.     //
  86.     int           YScrollValue(long rangeUnit);
  87.  
  88.     // Converts a horizontal scroll value from the scrollbar to
  89.     // a horizontal range value
  90.     //
  91.     long          XRangeValue(int scrollUnit);
  92.  
  93.     // Converts a vertical scroll value from the scrollbar to
  94.     // a vertical range value
  95.     //
  96.     long          YRangeValue(int scrollUnit);
  97.  
  98.   public:
  99.     TWindow*  Window;         // Window that this scroller belongs to
  100.     long      XPos;           // Current pos in horz/vert scroll units
  101.     long      YPos;           //
  102.     long      XRange;         // # of scrollable horz/vert scroll units
  103.     long      YRange;         //
  104.     long      XTotalUnits;    // Total number of horz/vert scroll units
  105.     long      YTotalUnits;    //
  106.     int       XUnit;          // Logical device units per horz/vert scroll unit
  107.     int       YUnit;          //
  108.     int       XLine;          // # of horz/vert scroll units per line
  109.     int       YLine;          //
  110.     int       XPage;          // # of horz/vert scroll units per page
  111.     int       YPage;          //
  112.     bool      AutoMode;       // Auto scrolling mode
  113.     bool      TrackMode;      // Track scroll mode
  114.     bool      AutoOrg;        // Indicates Scroller offsets origin
  115.     bool      HasHScrollBar;
  116.     bool      HasVScrollBar;
  117.  
  118.   DECLARE_STREAMABLE(_OWLCLASS, TScroller, 1);
  119. };
  120.  
  121. // Generic definitions/compiler options (eg. alignment) following the
  122. // definition of classes
  123. #include <services/posclass.h>
  124.  
  125. #if defined(BI_NAMESPACE)
  126. } // namespace OWL
  127. #endif
  128.  
  129. //----------------------------------------------------------------------------
  130. // Inline implementations
  131. //
  132.  
  133. //
  134. inline void TScroller::SetWindow(TWindow* win)
  135. {
  136.   Window = win;
  137. }
  138.  
  139. //
  140. inline void TScroller::ScrollBy(long dx, long dy)
  141. {
  142.   ScrollTo(XPos+dx, YPos+dy);
  143. }
  144.  
  145. //
  146. inline bool TScroller::IsVisibleRect(long x, long y, int xExt, int yExt)
  147. {
  148.   return (x + xExt > XPos) && (y + yExt > YPos) &&
  149.       (x <= XPos + XPage + 1) && (y <= YPos + YPage + 1);
  150. }
  151.  
  152. //
  153. inline int  TScroller::XScrollValue(long rangeUnit)
  154. {
  155.   return (int)LongMulDiv(rangeUnit, SHRT_MAX, XRange);
  156. }
  157.  
  158. //
  159. inline int  TScroller::YScrollValue(long rangeUnit)
  160. {
  161.   return (int)LongMulDiv(rangeUnit, SHRT_MAX, YRange);
  162. }
  163.  
  164. //
  165. inline long TScroller::XRangeValue(int scrollUnit)
  166. {
  167.   return LongMulDiv(scrollUnit, XRange, SHRT_MAX);
  168. }
  169.  
  170. //
  171. inline long TScroller::YRangeValue(int scrollUnit)
  172. {
  173.   return LongMulDiv(scrollUnit, YRange, SHRT_MAX);
  174. }
  175.  
  176. #endif  // OWL_SCROLLER_H
  177.